package top.go2do.tagCategory.business.category.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.go2do.common.controller.TomatoController;
import top.go2do.common.enumeration.CommonStatus;
import top.go2do.common.module.CategoryPO;
import top.go2do.common.module.UserInfoBO;
import top.go2do.common.module.pageQuery.PageResult;
import top.go2do.tagCategory.business.category.module.*;
import top.go2do.tagCategory.business.category.service.CategoryService;

import java.util.List;

/**
 * @Description
 * @Author xingyj
 * @CreateTime 2025/6/12 11:52
 */
@Slf4j
@RequestMapping("/categories")
@RestController
public class CategoryController implements TomatoController<CategoryListVO, CategoryCreateForm, CategoryModifyForm, Long, CategoryQueryCondition, CategoryQueryAllCondition, CategoryListVO> {

    @Autowired
    private CategoryService categoryService;

    @Override
    public CategoryListVO create(CategoryCreateForm createForm, UserInfoBO userInfo) {
        log.info("categories create appId:{}, categoryName:{}", userInfo.getAppId(), createForm.getCategoryName());
        createForm.setAppId(userInfo.getAppId());
        createForm.setUserId(userInfo.getUserId());
        if (createForm.getStatus() == null) {
            createForm.setStatus(CommonStatus.NORMAL.getValue());
        }
        return categoryService.create(createForm);
    }

    @Override
    public void modifyById(Long id, CategoryModifyForm modifyForm, UserInfoBO userInfo) {
        modifyForm.setCategoryId(id);
        modifyForm.setUserId(userInfo.getUserId());
        categoryService.modifyById(modifyForm);
    }

    @Override
    public void removeById(Long id, UserInfoBO userInfo) {
        categoryService.removeById(id);
    }

    @Override
    public CategoryListVO getById(Long id) {
        return categoryService.getById(id);
    }

    @Override
    public List<CategoryListVO> myListAll(UserInfoBO userInfo, CategoryQueryAllCondition categoryQueryAllCondition) {
        categoryQueryAllCondition.setUserId(userInfo.getUserId());
        return categoryService.listAll(categoryQueryAllCondition);
    }

    @Override
    public PageResult<CategoryListVO> myPageQuery(UserInfoBO userInfo, CategoryQueryCondition categoryQueryCondition) {
        categoryQueryCondition.setUserId(userInfo.getUserId());
        return categoryService.pageQuery(categoryQueryCondition);
    }
}
